<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>管理员列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">

</head>
<body>

<div class="layui-fluid" id="div4Add"  hidden >

    <div class="layui-card">
        <div class="layui-card-header">添加商品</div>
        <div class="layui-card-body">
            <form class="layui-form" action="" id="form1">
                <div class="layui-form-item">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="account"  placeholder="请输入账号"   lay-verify="required" autocomplete="off" class="layui-input" id="input-account">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password"   placeholder="请输入密码"  lay-verify="required" autocomplete="off" class="layui-input" id="input-password">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="displayname"   placeholder="请输入公司名称"  lay-verify="required" autocomplete="off" class="layui-input" id="input-displayname">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">身份证号</label>
                    <div class="layui-input-block">
                        <input type="text" name="id"   placeholder="请输入身份证号"  lay-verify="required" autocomplete="off" class="layui-input" id="input-id">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">电话号码</label>
                    <div class="layui-input-block">
                        <input type="text" name="phone"   placeholder="请输入电话号码"  lay-verify="required|number" autocomplete="off" class="layui-input" id="input-phone">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
                        <button type="button" class="layui-btn layui-btn-primary" id="goback">返回</button>
                    </div>
                </div>
            </form>
        </div>
    </div>


</div >


<div class="layui-fluid"  id="divMain" >


    <div class="layui-card">
        <div class="layui-card-header" layuiadmin-card-header-auto style="height: auto">管理员列表展示
            <!--search-->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width:30px">公司</label>
                    <div class="layui-input-inline">
                        <input type="text" name="companyname" id="search-companyname" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                &nbsp;
                <div class="layui-inline">
                    <label class="layui-form-label" style="width:30px">风格</label>
                    <div class="layui-input-inline">
                        <input type="text" name="style" id="search-style" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                &nbsp;
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 50px;" >代表作</label>
                    <div class="layui-input-inline">
                        <input type="text" name="masterpiece" id="search-masterpiece" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                &nbsp;
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="lay-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
            <!--search-->
        </div>
        <div class="layui-card-body">
            <table class="layui-table" id="table1" lay-filter="test"></table>
            <!--  lay-filter 相当于layui的专用id-->
        </div>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-xs" lay-event="add">添加</button>
        <button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="batchDelete">批量删除</button>
    </div>
</script>

<script type="text/html" id="tool1">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-xs layui-btn-primary" lay-event="deal"><i class="layui-icon layui-icon-edit"></i>下单</button>

        <button type="button" class="layui-btn layui-btn-xs layui-btn-radius layui-btn-primary layui-border-red" lay-event="detail">
            <i class="layui-icon layui-icon-delete"></i>详细信息
        </button>
    </div>
</script>






</body>
</html>
<script src="/layuiadmin/layui/layui.js"></script>
<script>




    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table',"tree","jquery","layer","form"], function(){
        var table = layui.table;
        var tree = layui.tree;
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table1;

        var addorupdate = false;

       // $("#hehe").html("666666");
        //加载左边树

        $(document).click(function(e) { // 在页面任意位置点击而触发此事件
            if($(e.target).attr('class') === "layui-tree-txt"){ // 防止因为点击展开按钮把已选中的样式取消
                $(".layui-tree-txt").removeClass("tree-txt-active"); // 移除点击样式
                $(e.target).addClass("tree-txt-active"); // e.target表示被点击的目标
            }
        });


        //展示已知数据
        function initTable(){
            table1 =  table.render({
                elem: '#table1'
                ,height: 'full-180'
                ,cols: [
                    [ //标题栏
                        {type: 'checkbox', fixed: 'left'}
                        ,{title:'#', type:'numbers', align:'center', width:40}
                        ,{field: 'pid', title: '主键', hide: true}
                        ,{field: 'pname', title: '演唱会名称', minWidth: 150, sort: true}
                        ,{field: 'releasetime', title: '发布时间', minWidth: 100}
                        ,{field: 'closetime', title: '截止时间', minWidth: 100}
                        ,{field: 'location', title: '地址', minWidth: 50}
                        ,{field: 'remnant', title: '余票数', minWidth: 150}
                        ,{field: 'price', title: '价格', minWidth: 150}
                        ,{title: '操作',toolbar:"#tool1", width:150}
                    ] ]
                //,url:"/getcompanyartist/"+$("#search-companyname").val()+"/"+$("#search-style").val()+"/"+$("#search-masterpiece").val()
                ,url:"/getperformances"
                ,page:true
                /*,request: {
                    pageName: 'pageNo'
                    ,limitName: 'pageSize'
                }*/
                ,even: true
                ,toolbar:"#toolbarDemo"
                ,defaultToolbar:["filter"]

            });
        }
        form.on('submit(lay-search)', function(data) {
            // data.field：存放表单所有数据
            table.reload('table1', {
                url: "/getcompanyartist/"+$("#search-companyname").val()+"/"+$("#search-style").val()+"/"+$("#search-masterpiece").val()
                ,where: data.field
            });
        });


        initTable();
        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    addorupdate = true;
                    $("#div4Add").show();
                    $("#divMain").hide();
                    $("#form1")[0].reset();//reset 原生js 方法
                    layer.close(layer.index);

                    break;
                case 'batchDelete':
                   var data = checkStatus.data;

                   if(data.length<=0){
                        layer.msg('未选中记录');
                        return;
                    }else{

                       layer.confirm('确认要删除吗', {icon: 3, title:''}, function(index){
                              var idTxt="";
                              var data = checkStatus.data;
                              $.each(data,function (i,d) {
                                  idTxt = idTxt+"id="+d.account+"&";
                              });
                              $.ajax({
                                  type: "POST",
                                  url: "/batchDeleteAdmin",
                                  data:idTxt,
                                  success: function(data){
                                      if(data.success){
                                          layer.msg("操作成功",{time:700},function () {
                                              table1.reload();
                                          });
                                      }
                                  },
                                  dataType:"json"
                              });

                            layer.close(index);
                        });

                    }

                    break;
            };
        });



        table.on('tool(test)', function(obj){
            var data = obj.data
            switch(obj.event){
                case 'deal':
                    layer.confirm('确认下单 【'+data.pname+ '】 吗', {icon: 3, title: ''}, function (index) {

                        $.ajax({
                            type: "POST",
                            url: "/usermakedeal",
                            data: "id="+data.pid,
                            success: function (data) {
                                if (data.success) {
                                    layer.msg("操作成功", {time: 700}, function () {
                                        //table1.reload();
                                    });
                                }
                                else {
                                    layer.msg("操作失败", {time: 700}, function () {
                                        //table1.reload();
                                    });
                                }
                            },
                            dataType: "json"
                        });

                        layer.close(index);
                    });

                    break;
                case 'detail':
                    layer.confirm('确认要删除 【'+data.displayname+ '】 吗', {icon: 3, title: ''}, function (index) {

                        $.ajax({
                            type: "POST",
                            url: "/oneDeleteAdmin",
                            data: "id="+data.account,
                            success: function (data) {
                                if (data.success) {
                                    layer.msg("操作成功", {time: 700}, function () {
                                        table1.reload();
                                    });
                                }
                            },
                            dataType: "json"
                        });

                        layer.close(index);
                    });


                    break;
            };
        });





       $("#goback").click(function () {
           $("#div4Add").hide();
           $("#divMain").show();
       });

        //监听提交
        form.on('submit(formDemo)', function(data){
            console.log(addorupdate);
            if (addorupdate == true){
                $.ajax({
                    type: "POST",
                    url: "/addAdmin",
                    data: data.field,
                    success: function (data) {
                        if (data.success) {
                            layer.msg("操作成功", {time: 700}, function () {
                                $("#div4Add").hide();
                                $("#divMain").show();
                                table1.reload();
                                //layer.msg(data.result);
                            });
                        }
                    },
                    dataType: "json"
                });
            }
            else if (addorupdate == false) {

                $.ajax({
                    type: "POST",
                    url: "/updateAdmin",
                    data: data.field,
                    success: function (data) {
                        if (data.success) {
                            layer.msg("操作成功", {time: 700}, function () {
                                $("#div4Add").hide();
                                $("#divMain").show();
                                table1.reload();
                                //layer.msg(data.result);
                            });
                        }
                    },
                    dataType: "json"
                });

            }


            return false;
        });

    });

</script>



</body>
</html>
